package api

import (
	"fmt"
	log "github.com/sirupsen/logrus"
	"math/rand"
	"os"
	"time"
)

var LocalStorePath string
var NodeAddr string
var MetaNodeAddr string

func Initval(localStorePath, nodeAddr, metanodeAddr string) {
	rand := rand.New(rand.NewSource(time.Now().UnixNano()))
	//随机十个大写字母数字
	bytes := make([]byte, 10)
	for i := 0; i < 10; i++ {
		b := rand.Intn(26) + 65
		bytes[i] = byte(b)
	}
	//生成文件存储的目录
	LocalStorePath = fmt.Sprintf("%s%s%s", localStorePath, string(os.PathSeparator), string(bytes))
	log.Debug("文件存储的目录:", LocalStorePath)
	//如果目录不存在，这新建该目录，授予目录权限为777

	//目录不存在则创建
	if _, err := os.Stat(LocalStorePath); os.IsNotExist(err) {
		os.MkdirAll(LocalStorePath, os.ModePerm)
	}
	NodeAddr = nodeAddr
	MetaNodeAddr = metanodeAddr

}
